#include "stdafx.h"
#include <string.h>
#include "ado/DbMysql.h"
#include "ado/Replaces.h"
#include "standard/nstring.h"
//#include "ado/fun_sets.h"
Replaces *Replaces::_init = NULL;

Replaces* Replaces::init(void *db)
{
    _init = new Replaces(db);
    return _init;
}

Replaces::Replaces(void *db)
{
    m_db = (tDataBase*) db; 
    std::string classname = m_db->classname;
    
    if (!(m_db->database).empty()) {
        m_dbname = m_db->database;
    }
    
    this->m_classname = tolower_str(classname);
	// GetFunInstance("tolower_str",this->m_classname,  classname );
}


Replaces::~Replaces()
{
    m_db->database.clear();
    m_db->classname.clear();
}

Replaces *Replaces::replacep(std::map<std::string, std::string> setstr)
{
    this->m_setstr    = setstr;
   // this->insertparam(this->m_setstr, this->m_classname);    
    
    return this;
}

int Replaces::create()
{
    std::string que;
    
    this->m_classname = tolower_str(this->m_classname);
    //    GetFunInstance("tolower_str",this->m_classname, this->m_classname );
    que = "Replace into " + m_dbname + "."  
                + m_prefix + this->m_classname + " (" 
                + this->getColumnOfStr(this->m_classname, this->m_setstr)
                + ") values (" 
                + this->getInsert() + ")" ;
    return DbMysql::instance()->execute(que.c_str())->insert_id();
}

